/*************************************************************************
    > File Name: main.cpp
    > Author: ZhaoLulu@BJTU
    > E-mail: 19281121@bjtu.edu.cn
    > Created Time: 2021年12月14日 星期二
 ************************************************************************/
#include "SHA1.h"
#include "SHA256.h"
#include <fstream>

string readFileIntoString(string filename) {
    ifstream in(filename);
    ostringstream buf;
    char ch;
    while (buf && in.get(ch)) {
        buf.put(ch);
    }
    return buf.str();
}

int main() {
    cout << "------------------------------------SHA1测试------------------------------------" << endl;
    cout << "原文：ZhaoLulu" << endl;
    cout << "SHA1值：" << SHA1("ZhaoLulu") << endl;
    cout << "文件测试：test.txt" << endl;
    string file = "test.txt";
    string str = readFileIntoString(file);
    cout << "SHA1值：" << SHA1(str) << endl;

    cout << "--------------------------------------------------------------------------------" << endl << endl;
    cout << "-----------------------------------SHA256测试-----------------------------------" << endl;
    cout << "原文：ZhaoLulu" << endl;
    UChar Y[] = "ZhaoLulu";
    SHA256 sha256;
    cout << "SHA256值：" << sha256.DO(Y) << endl;
    cout << "文件测试：test.txt" << endl;
    int len = str.length();
    for (int i = 0; i < len; ++i) {
        Y[i] = str[i];
    }
    Y[len] = '\0';
    cout << "SHA256值：" << sha256.DO(Y) << endl;
    cout << "--------------------------------------------------------------------------------" << endl;
    return 0;
}
